﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using XiMiBll;
using XiMiModel;
using XiMiModelDto;

namespace XiaoMiAPI.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class XiaoMiController : ControllerBase
    {
        private readonly PhoneBll _phoneBll;
        public XiaoMiController(PhoneBll phoneBll)
        {
            _phoneBll = phoneBll;
        }
        [HttpGet]
        public IActionResult Show(string gname,int pageindex=1, int pagesize=8)
        {
            var totalcount = 0;
            var list = _phoneBll.Show(pageindex, pagesize, gname, out totalcount);
            return Ok(new { list, totalcount });
        }
        [HttpPost]
        public IActionResult Login(string uname, string password)
        {
            return Ok(_phoneBll.Login(uname, password));
            //var list = _phoneBll.Login(uname, password);
            //if(list!=null)
            //{
            //    return Ok(new { code = 1, msg = "登录成功", data = "" });
            //}
            //else
            //{
            //    return Ok(new { code = 0, msg = "登录失败", data = "" });
            //}
        }
        [HttpPost]
        public IActionResult Register(UserModel userModel)
        {
            return Ok(_phoneBll.Register(userModel));
        }
        [HttpGet]
        public IActionResult Fan(int id)
        {
            return Ok(_phoneBll.Fan(id));
        }
        [HttpPost]
        public IActionResult Add(ShopModel shopModel)
        {
            return Ok(_phoneBll.Add(shopModel));
        }
    }
}
